package com.lagou.product.controller;

import com.lagou.common.pojo.Products;
import com.lagou.product.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.persistence.criteria.CriteriaBuilder;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;


    /**
     * 根据商品ID查询商品对象
     */
    @RequestMapping("/query/{id}")
    public Products query(@PathVariable Integer id){
        return productService.findById(id);
    }

    /**
     * 根据商品ID修改
     */
    @RequestMapping("/update/{id}")
    public int update1(Products products){
     // Products products = new Products();
     products.setName("华为111");
     products.setPrice(19999);
     products.setFlag("1");

     return productService.updateById(products);
     }

     /**
     * 根据商品ID删除
     */
    @RequestMapping("/delete/{id}")
    public int delete(@PathVariable Integer id){
        return productService.deleteById(id);
    }

}
